package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.happy.cat.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.UserApplyWithdraw;
import com.happy.cat.project.system.service.IUserApplyWithdrawService;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.happy.cat.framework.web.page.TableDataInfo;

/**
 * 用户提现申请Controller
 *
 * @author verne
 * @date 2020-08-29
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userApplyWithdraw" )
@Api("用户提现申请 API")
public class UserApplyWithdrawController extends BaseController {

    private final IUserApplyWithdrawService iUserApplyWithdrawService;

    /**
     * 查询用户提现申请列表
     */
    @ApiOperation(value = "查询用户提现申请列表",notes = "查询用户提现申请列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userApplyWithdraw:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserApplyWithdraw userApplyWithdraw)
    {
        startPage();
        LambdaQueryWrapper<UserApplyWithdraw> lqw = new LambdaQueryWrapper<UserApplyWithdraw>();
        if (StringUtils.isNotBlank(userApplyWithdraw.getCode())){
            lqw.eq(UserApplyWithdraw::getCode ,userApplyWithdraw.getCode());
        }
        if (StringUtils.isNotBlank(userApplyWithdraw.getAccountName())){
            lqw.like(UserApplyWithdraw::getAccountName ,userApplyWithdraw.getAccountName());
        }
        if (userApplyWithdraw.getTakeMoney() != null){
            lqw.eq(UserApplyWithdraw::getTakeMoney ,userApplyWithdraw.getTakeMoney());
        }
        if (userApplyWithdraw.getUasFavor() != null){
            lqw.eq(UserApplyWithdraw::getUasFavor ,userApplyWithdraw.getUasFavor());
        }
        if (userApplyWithdraw.getLeftoverFavor() != null){
            lqw.eq(UserApplyWithdraw::getLeftoverFavor ,userApplyWithdraw.getLeftoverFavor());
        }
        if (userApplyWithdraw.getRate() != null){
            lqw.eq(UserApplyWithdraw::getRate ,userApplyWithdraw.getRate());
        }
        if (userApplyWithdraw.getArriveMoney() != null){
            lqw.eq(UserApplyWithdraw::getArriveMoney ,userApplyWithdraw.getArriveMoney());
        }
        if (userApplyWithdraw.getChannel() != null){
            lqw.eq(UserApplyWithdraw::getChannel ,userApplyWithdraw.getChannel());
        }
        if (userApplyWithdraw.getStatus() != null){
            lqw.eq(UserApplyWithdraw::getStatus ,userApplyWithdraw.getStatus());
        }
        if (userApplyWithdraw.getApplyTime() != null){
            lqw.eq(UserApplyWithdraw::getApplyTime ,userApplyWithdraw.getApplyTime());
        }
        if (StringUtils.isNotBlank(userApplyWithdraw.getApplyText())){
            lqw.eq(UserApplyWithdraw::getApplyText ,userApplyWithdraw.getApplyText());
        }
        if (StringUtils.isNotBlank(userApplyWithdraw.getApplyBy())){
            lqw.eq(UserApplyWithdraw::getApplyBy ,userApplyWithdraw.getApplyBy());
        }
        List<UserApplyWithdraw> list = iUserApplyWithdrawService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户提现申请列表
     */
    @ApiOperation(value = "导出用户提现申请列表",notes = "导出用户提现申请列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userApplyWithdraw:export')" )
    @Log(title = "用户提现申请" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserApplyWithdraw userApplyWithdraw) {
        LambdaQueryWrapper<UserApplyWithdraw> lqw = new LambdaQueryWrapper<UserApplyWithdraw>(userApplyWithdraw);
        List<UserApplyWithdraw> list = iUserApplyWithdrawService.list(lqw);
        ExcelUtil<UserApplyWithdraw> util = new ExcelUtil<UserApplyWithdraw>(UserApplyWithdraw. class);
        return util.exportExcel(list, "userApplyWithdraw" );
    }

    /**
     * 获取用户提现申请详细信息
     */
    @ApiOperation(value = "获取用户提现申请详细信息",notes = "获取用户提现申请详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userApplyWithdraw:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserApplyWithdrawService.getById(id));
    }

    /**
     * 新增用户提现申请
     */
    @ApiOperation(value = "新增用户提现申请",notes = "新增用户提现申请",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userApplyWithdraw:add')" )
    @Log(title = "用户提现申请" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserApplyWithdraw userApplyWithdraw) {
        return toAjax(iUserApplyWithdrawService.save(userApplyWithdraw) ? 1 : 0);
    }

    /**
     * 修改用户提现申请
     */
    @ApiOperation(value = "修改用户提现申请",notes = "修改用户提现申请",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userApplyWithdraw:edit')" )
    @Log(title = "用户提现申请" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserApplyWithdraw userApplyWithdraw) {
        return toAjax(iUserApplyWithdrawService.updateById(userApplyWithdraw) ? 1 : 0);
    }

    /**
     * 删除用户提现申请
     */
    @ApiOperation(value = "删除用户提现申请",notes = "删除用户提现申请",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userApplyWithdraw:remove')" )
    @Log(title = "用户提现申请" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserApplyWithdrawService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
